package movee.domain.constants;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.Map;

/**
 *
 *
 * @author movee
 */
@Getter
@AllArgsConstructor
public enum BackupTaskPriority {

    LOW(0, "low", ""),
    MIDDLE(1, "midlle", ""),
    HIGH(2, "high", "");

    private final int id;
    private final String chineseName;
    private final String description;

    private static final Map<String, BackupTaskPriority> CHINESE_MAP = new HashMap<>();
    private static final Map<String, BackupTaskPriority> NAME_MAP = new HashMap<>();
    private static final Map<String, BackupTaskPriority> ID_MAP = new HashMap<>();

    static {
        for (BackupTaskPriority status : BackupTaskPriority.values()) {
            CHINESE_MAP.put(status.getChineseName(), status);
            NAME_MAP.put(StringUtils.upperCase(status.name()), status);
            ID_MAP.put(String.valueOf(status.id), status);
        }
    }

    public static BackupTaskPriority fromChineseName(String chineseName) {
        return chineseName == null ? null : CHINESE_MAP.get(chineseName);
    }

    public static BackupTaskPriority fromName(String name) {
        return name == null ? null : NAME_MAP.get(StringUtils.upperCase(name));
    }

    public static BackupTaskPriority fromId(String id) {
        return id == null ? null : ID_MAP.get(id);
    }
}
